package com.ywjt.platformbusiness.widget;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ywjt.platformbusiness.R;


/**
 * 自定义加载中Dialog
 */

public class LoadingDialog extends ProgressDialog {
    private Context context;
    private String msg;

    public LoadingDialog(Context context, String msg) {
        super(context, R.style.LoadingDialog);
        this.context = context;
        this.msg = msg;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    private void init() {
        // 设置返回键无效
        //设置不可取消，点击其他区域不能取消，实际中可以抽出去封装供外包设置
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        setContentView(R.layout.dialog_loading);
        ImageView ivLoading = findViewById(R.id.ivLoading);
        TextView tvLoading = findViewById(R.id.tvLoading);

        Glide.with(context).load(R.mipmap.loading_progross).into(ivLoading);
        if ("".equals(msg)) {
            tvLoading.setText("加载中");
        } else {
            tvLoading.setText(msg);
        }
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(params);
    }

    @Override
    public void show() {
        super.show();
    }
}
